package br.com.amadeus.android.activities.course;

import java.util.List;

import br.com.amadeus.android.activities.home.R;
import br.com.amadeus.android.adapters.MyCoursesListAdapter;
import br.com.amadeus.android.business.FacadeAmadeusDroid;
import br.com.amadeus.android.entities.Course;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class CourseOnActivity extends Activity {

	public static final int INACTIVE = 0;
	public static final int SAIR = 1;
	private ListView listView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		//video libras
		setContentView(R.layout.amadeus_screen_mycourses);
		ImageButton librasBt = (ImageButton)findViewById(R.id.botaoLibras4);
	        librasBt.setOnClickListener(new OnClickListener() {
				
				public void onClick(View arg0) {
					Intent it = new Intent("ABRIR_LIBRAS");
					it.putExtra("video_libras", "CourseOn.wmv");
					startActivity(it);
					
				}
			});
		
		List<Course> listCourses = FacadeAmadeusDroid.getInstance(this).getListActiveCourses();
		System.out.println(listCourses.get(0));
		
		MyCoursesListAdapter adapter = new MyCoursesListAdapter(this, listCourses);
		
		this.listView = (ListView) findViewById(R.id.lvMyCourses);
		this.listView.setAdapter(adapter);
		System.out.println("LISTAAAA"+this.listView.toString());
		
		this.listView.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> parent, View v, int posicao, long id) {
				
				Course course = (Course) listView.getAdapter().getItem(posicao);
				
				Intent it = new Intent("HOME_COURSE");
				Bundle basket = new Bundle();
				basket.putInt("course_id", course.getId());
				it.putExtras(basket);
				startActivity(it);
				
			}
		});
		
	}
	
	@Override
	public boolean onCreateOptionsMenu(android.view.Menu menu) {
		super.onCreateOptionsMenu(menu);
		
		MenuItem item = menu.add(0, INACTIVE, 0, "Cursos Inativos");
				
		return true;
	}
	@Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
		switch (item.getItemId()) {
		case INACTIVE:
			startActivity(new Intent("COURSEOFF"));
			return true;
						
		}
		return false;
	}
}